unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMainForm = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button4: TButton;
    PathEdit: TEdit;
    FrameTimeEdit: TEdit;
    RepeatCountEdit: TEdit;
    Label4: TLabel;
    ResultLabel: TLabel;
    procedure Button4Click(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

const
  mrError = -1;

function InitializeIntro(WindowOwner: HWND; SourcePath: PWideChar;
  FrameTime: Integer): Integer; stdcall;
  external '..\ImageAnimator.dll' name 'IPInitializeIntro';
function InitializeAnimation(WindowOwner: HWND; SourcePath: PWideChar;
  FrameTime: Integer; RepeatCount: Integer): Integer; stdcall;
  external '..\ImageAnimator.dll' name 'IPInitializeAnimation';

implementation

{$R *.dfm}

procedure TMainForm.Button4Click(Sender: TObject);
var
  Result: Integer;
  FrameTime: Integer;
  RepeatCount: Integer;
begin
  ResultLabel.Caption := '---';
  ResultLabel.Font.Color := clBlack;
  TryStrToInt(FrameTimeEdit.Text, FrameTime);
  TryStrToInt(RepeatCountEdit.Text, RepeatCount);
  Result := InitializeAnimation(MainForm.Handle, PWideChar(PathEdit.Text), FrameTime, RepeatCount);
  case Result of
    mrOk: ResultLabel.Caption := 'Animation has been fully played!';
    mrCancel: ResultLabel.Caption := 'Animation has been closed during playback!';
    mrError: ResultLabel.Caption := 'Initialization error!';
  end;
  if Result = mrOk then
    ResultLabel.Font.Color := clGreen
  else
    ResultLabel.Font.Color := clRed;
end;

procedure TMainForm.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const
  SC_DRAGMOVE = $F012;
begin
  if Button = mbLeft then
  begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
  end;
end;

end.
